#!/bin/bash
portarray=(`ss --listening --tcp --numeric |grep "*:"| grep -v "127.0.0.1" |sed 's/ //g'| awk -F'*:' '{if ($2~/'[0-9]+'/) print $2}'`)
length=${#portarray[@]}
printf "{\n"
printf  '\t'"\"data\":["
for ((i=0;i<$length;i++))
  do
     printf '\n\t\t{'
     printf "\"{#TCP_PORT}\":\"${portarray[$i]}\"}"
     if [ $i -lt $[$length-1] ];then
                printf ','
     fi
  done
printf  "\n\t]\n"
printf "}\n"